<?php


namespace app\api\controller;


use app\common\model\VoteResult;
use think\facade\Db;

class Vote extends ApiBase
{

    //用户投票
    public function userVote(){
        $id = input("id");
        $vote = input("vote");
        $res = VoteResult::create(["vote_id" => $id,"result" => $vote,"uid" => $this->uid]);
        if ($res){

            foreach ($vote as $item){
                Db::name("vote_option")->where("id",$item)->inc('ticket_num')->update();
            }

            return notice("投票成功");
        }

        return error("投票失败");
    }
}